package com.bcxj.servicepay.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.checkerframework.checker.units.qual.C;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * ClassName: AlipayConfig
 * Package: com.bcxj.servicepay.config
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/11/24 17:59
 * @Version 1.0
 * @Since 1.0
 */
@Component
@ConfigurationProperties(prefix = "alipay")
@Data
public class AlipayConfig {
    private String appId;
    private String appPrivateKey;
    private String publicKey;
    private String notifyUrl;

    // Bean的生命周期函数
    @PostConstruct
    public void init() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = appId;
        config.merchantPrivateKey = appPrivateKey;
        config.alipayPublicKey = publicKey;
        config.notifyUrl = notifyUrl;
        Factory.setOptions(config);
        System.out.println("支付宝配置初始化成功");
    }

}
